package View.GUI;

import java.awt.Graphics;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.net.URL;

import javax.swing.ImageIcon;


import Controller.Game.GamePanelController;
import Model.Visible.Fleet;
import Utils.ConstantsImplement;
import Utils.Utils;
import Utils.Timers.Timer;
import Utils.Timers.TimerListener;
import View.Game.GamePanel;

public class FleetGUI implements ConstantsImplement, TimerListener{
	
	private BufferedImage image_;
	private Fleet fleet_;
	private Timer timer_;
	private GamePanelController gamePanelController_;
	private int image_iterator_ = 0;

	
	public BufferedImage getImage(){
		return image_;
	}
	
	public Fleet getFleet(){
		return fleet_;
	}
	
	public FleetGUI(Fleet fleet, GamePanelController gamePanelController ){
		fleet_ = fleet;
		gamePanelController_ = gamePanelController;
		URL url = GamePanel.class.getResource("/Image/FleetAnimaltion/FleetAnima1.png");
		image_ = Utils.toBufferedImage((new ImageIcon(url)).getImage());
		timer_ = new Timer(this, 50);
		timer_.start();
	}
	
	public void draw(Graphics g){
			g.drawImage(image_, (int)fleet_.getPosition_().getX(), (int)fleet_.getPosition_().getY(),
					FLEET_SIZE_X, FLEET_SIZE_Y, null);
	}
	
	public void update(){
		image_iterator_++;
		if( image_iterator_ >= 13 ){
			image_iterator_ = 1;
		}
		
		if(fleet_.getOwner_().getRace_() == NYAN_RACE && fleet_.getVx() >= 0){
			URL url = GamePanel.class.getResource("/Image/FleetAnimaltion/FleetAnima"+image_iterator_+".png");
			image_ = Utils.toBufferedImage((new ImageIcon(url)).getImage());
		}
		if(fleet_.getOwner_().getRace_() == NYAN_RACE && fleet_.getVx() < 0){
			URL url = GamePanel.class.getResource("/Image/FleetAnimaltion/FleetAnima"+image_iterator_+"e.png");
			image_ = Utils.toBufferedImage((new ImageIcon(url)).getImage());
		}
		if(fleet_.getOwner_().getRace_() == NAYN_RACE && fleet_.getVx() >= 0){
			URL url = GamePanel.class.getResource("/Image/TacnaynAnima/tacnaynAnima"+image_iterator_+".png");
			image_ = Utils.toBufferedImage((new ImageIcon(url)).getImage());
		}
		if(fleet_.getOwner_().getRace_() == NAYN_RACE && fleet_.getVx() < 0){
			URL url = GamePanel.class.getResource("/Image/TacnaynAnima/tacnaynAnima"+image_iterator_+"e.png");
			image_ = Utils.toBufferedImage((new ImageIcon(url)).getImage());
		}
		
		//gamePanelController_.updateFleet();
	}
	

}
